

package org.come.Jpanel;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.ShaoXiangBtn;
import com.tool.tcpimg.UIUtils;
import org.cbg.btn.TrslationBtn;
import org.come.bean.ShaoXiangLimit;
import org.come.entity.Goodstable;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.UserMessUntil;
import org.skill.panel.EquipmentJpanel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.math.BigDecimal;
import java.util.concurrent.ConcurrentHashMap;

public class ShaoXiangJpanel extends JPanel {

    private JLabel chooseLeft;
    private TrslationBtn chooseLeftArrows;
    private EquipmentJpanel optionJpanel;

    private JLabel chooseItemLeft;
    private TrslationBtn chooseItemLeftArrows;
    private EquipmentJpanel optionItemJpanel;
    private ShaoXiangBtn btnmount;
    private int leftFlag;
    private int leftItemFlag;
    private ImageIcon icon;
    private ImageIcon licon = new ImageIcon("img/xy2uiimg/78_png.xy2uiimg.btn_plock.png");
    private JProgressBar jProgressBar;

    private int xianghuoNum = 0;

    public ShaoXiangJpanel() {
        icon = new ImageIcon("inkImg/background/shgf.png");
        this.setPreferredSize(new Dimension(320, 393));
        this.setLayout(null);
        this.setBackground(UIUtils.Color_BACK);
        FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/button/1.png", 1, 636);
        offBtn.setBounds(320 - 40, 10, 25, 25);
        this.add(offBtn);

        this.setLayout(null);
        this.setBackground(UIUtils.Color_BACK);
        String[] rowData = {};
        if (UserMessUntil.getAllshaoxiang() != null && UserMessUntil.getAllshaoxiang().size() > 0) {
            rowData = UserMessUntil.getAllshaoxiang().toArray(new String[0]);
            this.chooseLeft = new JLabel(UserMessUntil.getAllshaoxiang().get(0));
        } else {
            this.chooseLeft = new JLabel("人物经验(1/次)");
        }
        (this.chooseLeftArrows = new TrslationBtn("inkimg/background/xiaanniu.png", 1)).setBounds(260, 43, 19, 20);
        this.chooseLeftArrows.setOpaque(false);
        this.add((Component) this.chooseLeftArrows);

        (this.optionJpanel = new EquipmentJpanel(140, 120, rowData)).setVisible(false);
        this.optionJpanel.setBounds(140, 62, 140, 120);
        this.add((Component) this.optionJpanel);
        this.chooseLeftArrows.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(final MouseEvent e) {
                if (ShaoXiangJpanel.this.leftFlag == 1) {
                    ShaoXiangJpanel.this.optionJpanel.setVisible(true);
                    ShaoXiangJpanel.this.leftFlag = 0;
                } else {
                    ShaoXiangJpanel.this.optionJpanel.setVisible(false);
                    ShaoXiangJpanel.this.leftFlag = 1;
                }
            }
        });
        this.optionJpanel.getJlist().addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(final MouseEvent e) {
                final String getname = (String) ShaoXiangJpanel.this.optionJpanel.getJlist().getSelectedValue();
                ShaoXiangJpanel.this.chooseLeft.setText(getname);
                ShaoXiangJpanel.this.optionJpanel.setVisible(false);
                ShaoXiangJpanel.this.leftFlag = 1;

                if (getname.startsWith("装备特技")) {
                    ShaoXiangJpanel.this.chooseItemLeft.setEnabled(true);
                    ShaoXiangJpanel.this.optionItemJpanel.setVisible(false);
                    ShaoXiangJpanel.this.chooseItemLeftArrows.setEnabled(true);
                } else {
                    ShaoXiangJpanel.this.chooseItemLeft.setEnabled(false);
                    ShaoXiangJpanel.this.optionItemJpanel.setVisible(false);
                    ShaoXiangJpanel.this.chooseItemLeftArrows.setEnabled(false);
                }
            }
        });

        btnmount = new ShaoXiangBtn("inkImg/background/B20.png", 1, UIUtils.COLOR_BLACK, 1, "烧香", this);
        btnmount.setBounds(160, 350, 59, 24);
        this.add(btnmount);

        this.chooseLeft.setForeground(Color.white);
        this.chooseLeft.setFont(UIUtils.TEXT_FONT2);
        this.chooseLeft.setBounds(150, 42, 154, 20);
        this.add((Component) this.chooseLeft);

        this.jProgressBar = new JProgressBar();
        this.jProgressBar.setStringPainted(true);
        this.jProgressBar.setBounds(114, 304, 160, 18);
        this.add(jProgressBar);

        this.chooseItemLeft = new JLabel("武器");
        ShaoXiangJpanel.this.chooseItemLeft.setEnabled(false);
        (this.chooseItemLeftArrows = new TrslationBtn("inkimg/background/xiaanniu.png", 1)).setBounds(260, 78, 19, 20);
        ShaoXiangJpanel.this.chooseItemLeftArrows.setEnabled(false);
        this.chooseItemLeftArrows.setOpaque(false);
        this.add((Component) this.chooseItemLeftArrows);

        String[] rowItemData = {"武器", "帽子", "项链", "衣服", "护身符", "鞋子"};   //0武器、1 头部、2项链、3衣服、4护符、5鞋子、6面具、7、束带、8 披风、9挂饰、10左戒指、11右戒指、
        (this.optionItemJpanel = new EquipmentJpanel(140, 120, rowItemData)).setVisible(false);
        ShaoXiangJpanel.this.optionItemJpanel.setVisible(false);
        this.optionItemJpanel.setBounds(140, 97, 140, 120);
        this.add((Component) this.optionItemJpanel);
        this.chooseItemLeftArrows.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(final MouseEvent e) {
                if (chooseItemLeftArrows.isEnabled()) {
                    if (ShaoXiangJpanel.this.leftItemFlag == 1) {
                        ShaoXiangJpanel.this.optionItemJpanel.setVisible(true);
                        ShaoXiangJpanel.this.leftItemFlag = 0;
                    } else {
                        ShaoXiangJpanel.this.optionItemJpanel.setVisible(false);
                        ShaoXiangJpanel.this.leftItemFlag = 1;
                    }
                }
            }
        });
        this.optionItemJpanel.getJlist().addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(final MouseEvent e) {
                final String getname = (String) ShaoXiangJpanel.this.optionItemJpanel.getJlist().getSelectedValue();
                ShaoXiangJpanel.this.chooseItemLeft.setText(getname);
                ShaoXiangJpanel.this.optionItemJpanel.setVisible(false);
                ShaoXiangJpanel.this.leftItemFlag = 1;

            }
        });

        this.chooseItemLeft.setForeground(Color.white);
        this.chooseItemLeft.setFont(UIUtils.TEXT_FONT2);
        this.chooseItemLeft.setBounds(150, 77, 154, 20);
        this.add((Component) this.chooseItemLeft);
        this.setXianghuoNum();
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
            g.drawImage(icon.getImage(), 0, 0, 320, 393, this);
            g.setColor(Color.BLACK);
            g.setFont(UIUtils.TEXT_FONT1);
            String slectstr = ShaoXiangJpanel.this.chooseLeft.getText();
            ConcurrentHashMap<String, ShaoXiangLimit> alllimit = UserMessUntil.getAllshaoxianglimit();
            if(slectstr !=null && alllimit!=null){
                ShaoXiangLimit shaoXianglimit = alllimit.get(slectstr);
                g.drawString(String.valueOf(shaoXianglimit==null?0:shaoXianglimit.getNum()) + "/"+String.valueOf(shaoXianglimit==null?0:shaoXianglimit.getLimit()), 170, 262);
            }else {
                g.drawString("0/0", 170, 262);
            }
            g.drawString(String.valueOf(xianghuoNum), 170, 292);
            if(this.optionJpanel.getListModel()==null || this.optionJpanel.getListModel().size()<=0 ){
                if ( UserMessUntil.getAllshaoxiang() != null ) {
                    int i = 0;
                    for (String entry: UserMessUntil.getAllshaoxiang()) {
                        this.optionJpanel.getListModel().add(i, entry);
                        ++i;
                    }
                }
            }
            this.setXianghuoNum();
    }

    public JLabel getChooseLeft() {
        return chooseLeft;
    }

    public void setChooseLeft(JLabel chooseLeft) {
        this.chooseLeft = chooseLeft;
    }

    public TrslationBtn getChooseLeftArrows() {
        return chooseLeftArrows;
    }

    public void setChooseLeftArrows(TrslationBtn chooseLeftArrows) {
        this.chooseLeftArrows = chooseLeftArrows;
    }

    public EquipmentJpanel getOptionJpanel() {
        return optionJpanel;
    }

    public void setOptionJpanel(EquipmentJpanel optionJpanel) {
        this.optionJpanel = optionJpanel;
    }

    public ShaoXiangBtn getBtnmount() {
        return btnmount;
    }

    public void setBtnmount(ShaoXiangBtn btnmount) {
        this.btnmount = btnmount;
    }

    public int getLeftFlag() {
        return leftFlag;
    }

    public void setLeftFlag(int leftFlag) {
        this.leftFlag = leftFlag;
    }

    public ImageIcon getIcon() {
        return icon;
    }

    public void setIcon(ImageIcon icon) {
        this.icon = icon;
    }

    public ImageIcon getLicon() {
        return licon;
    }

    public void setLicon(ImageIcon licon) {
        this.licon = licon;
    }

    public JProgressBar getjProgressBar() {
        return jProgressBar;
    }

    public void setjProgressBar(JProgressBar jProgressBar) {
        this.jProgressBar = jProgressBar;
    }

    public int getXianghuoNum() {
        return xianghuoNum;
    }

    public void setXianghuoNum() {
        Goodstable goodstable = UserMessUntil.getgoodstable(new BigDecimal(90002));
        this.xianghuoNum =  GoodsListFromServerUntil.getGoodNum(goodstable.getGoodsid());
    }

    public JLabel getChooseItemLeft() {
        return chooseItemLeft;
    }

    public void setChooseItemLeft(JLabel chooseItemLeft) {
        this.chooseItemLeft = chooseItemLeft;
    }

    public TrslationBtn getChooseItemLeftArrows() {
        return chooseItemLeftArrows;
    }

    public void setChooseItemLeftArrows(TrslationBtn chooseItemLeftArrows) {
        this.chooseItemLeftArrows = chooseItemLeftArrows;
    }
}
